package com.qsbg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsbg.entity.Dynamic;
import com.qsbg.entity.vo.DynamicPageVo;
import com.qsbg.entity.vo.DynamicUserActivityVo;
import com.qsbg.entity.vo.ResultVo;
import com.qsbg.mapper.DynamicMapper;
import com.qsbg.service.DynamicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DynamicServiceImpl extends ServiceImpl<DynamicMapper, Dynamic> implements DynamicService {

    @Resource
    private DynamicMapper dynamicMapper;

    public ResultVo getDynamics(DynamicPageVo dynamicPageVo){
        try{
            QueryWrapper<DynamicUserActivityVo> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.ne("t.deleted",1);
            queryWrapper1.like("t1.real_name", dynamicPageVo.getRealName());
            queryWrapper1.like("t2.activity_name", dynamicPageVo.getActivityName());
            queryWrapper1.like("t1.profile_id",dynamicPageVo.getProfileId());
            queryWrapper1.orderByDesc("update_time");
            Page<DynamicUserActivityVo> page1 = new Page<>(dynamicPageVo.getPageNum(),dynamicPageVo.getPageSize());
            IPage<DynamicUserActivityVo> dynamicIPage = dynamicMapper.getDynamicList(page1,queryWrapper1);
            return ResultVo.ok(dynamicIPage);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVo.fail("分页查询出错");
        }
    }


    public ResultVo getDynamic(Integer id){
        try{
            DynamicUserActivityVo dynamic = dynamicMapper.getDynamic(id);
            return ResultVo.ok(dynamic);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVo.fail("查询活动出错");
        }
    }
}
